package com.weavernorth.humanaffairs;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.io.UnsupportedEncodingException;

/**
 * 终端入职流程更新店铺信息表店经理字段
 */


public class EntryUpStoreAction implements Action {
    public static Log log = LogFactory.getLog(EntryUpStoreAction.class.getName());

    @Override
    public String execute(RequestInfo requestInfo) {
        BaseBean bb = new BaseBean();
        //数据库操作
        RecordSet rs = new RecordSet();
        RecordSet rsUp = new RecordSet();
        //请求id
        String strRequestid = requestInfo.getRequestid();
        //表名
        String strTable = requestInfo.getRequestManager().getBillTableName();
        //查询当前数据
        String strSql = "select fm.hth,fm.gw,fm.bm,hj.jobtitlename from " + strTable + " fm,hrmjobtitles hj where fm.gw=hj.id and fm.requestid=?";
        log.info("入职流程操作店铺信息表sql:" + strSql + ",requestid:" + strRequestid);
        rs.executeQuery(strSql, strRequestid);
        if (rs.next()) {
            //岗位名称
            String strJobName = Util.null2String(rs.getString("jobtitlename"));
            log.info("当前岗位名称:"+strJobName);
            //店铺id
            String strBm = Util.null2String(rs.getString("bm"));
            //人员编码
            String strWorkcode = Util.null2String(rs.getString("hth"));
            //获取店经理的名称
            String strMangername="";
            try{
             strMangername = new String(bb.getPropValue("mangerjobname", "mangername").getBytes("iso8859-1"), "utf-8");
            log.info("配置文件中,岗位名称:"+strMangername);
            }catch (UnsupportedEncodingException e){
                e.printStackTrace();
            }
            //如果为店经理,则更新店铺信息表的店长为空
            if (strJobName.equals(strMangername)) {
                String strUpsql = "update uf_dpxx set djlbh='" + strWorkcode + "' where dp=?";
                log.info("入职流程更新店铺信息表sql:" + strUpsql + ",djlbh:" + strWorkcode);
                rsUp.executeUpdate(strUpsql, strBm);
            }


        }
        return SUCCESS;
    }
}



